import uuid

from django.db import models
import django.utils.timezone as timezone
from django.db.backends.postgresql.base import DatabaseFeatures
DatabaseFeatures.supports_microsecond_precision = False

# CHANGELOG
'''
1. 不再保留 Function_Group_EN 这样的字段，之后直接mapping出结果
2. 不再保留车型的德文中文对照表，只有英文车型对照表
3. 不再翻译为德文，只保留中文和英文的翻译结果
'''

'''
1. 将Quality相关的数据库分开保存
'''

def generate_unique_id():
    unique_id = uuid.uuid4().hex
    return unique_id

class BaseModel(models.Model):
    uuid = models.CharField(primary_key=True,
                          max_length=32,
                          default=generate_unique_id,
                          unique=True)
    create_time = models.DateTimeField(
        verbose_name='create_time',
        editable=True,
        # auto_now_add=True
    )


    class Meta:
        ordering = ['-create_time']
        abstract = True


class TicketModel(BaseModel):

    '''
    TicketModel
    {
        "_url_unique": "/zlts/20231031/1041369.shtml",
        "url": "http://m.12365auto.com/zlts/20231031/1041369.shtml",
        "sourceId": "complaint_12365auto",
        "source_web_origin": "12365auto",
        "save_source_image": "yes",
        "info_category": "complaint",
        "title": "上汽大众途昂X变速箱过不平路面有咔咔异响",
        "text": "车辆行驶减速带，时候变速箱出现咔咔异响，去经销商检查告知没有问题，这几天行驶观察还是有咔咔异响声音。",
        "brand_src": "上汽大众",
        "series_src": "途昂X",
        "model_src": "2023款 380TSI 四驱 尊崇豪华版",
        "image_urls": "[]"
    }
    '''

    info_category_choices = (
        ('forum', 'forum'),
        ('complaint', 'complaint'),
        ('cuzu', 'cuzu'),
    )
    language_type_choices = (
        ('zh', 'zh'),
        ('en', 'en')
    )
    update_time = models.DateTimeField(
        verbose_name='update_time',
        editable=True,
        # auto_now=True
    )
    info_category = models.CharField(
        max_length=20, verbose_name='source_web_type', null=False, blank=False,
        choices=info_category_choices,
        default='complaint'
    )
    source_web_origin = models.CharField(
        max_length=30, verbose_name='source_web_origin', null=False, blank=False, default=''
    )
    save_source_image = models.CharField(
        max_length=10, verbose_name='save_source_image', null=False, blank=False, default='no'
    )

    # 重要的字段
    URL = models.CharField(
        max_length=400, verbose_name='URL', null=True, blank=True, default=''
    )

    sourceId = models.CharField(
        max_length=30, verbose_name='sourceId', null=False, blank=False, default=''
    )
    FLAG_function_group_problem = models.BooleanField(
        verbose_name='FLAG_function_group_problem'
    )

    function_group_problem = models.TextField(
        verbose_name='function_group_problem', null=True, blank=True, default=''
    )
    function_group_problem_en = models.TextField(
        verbose_name='function_group_problem_en', null=True, blank=True, default=''
    )



    # TODO : 这个NCVQS后续整理数据的时候，将长度进行更改，节省数据库
    FLAG_ncvqs = models.BooleanField(
        verbose_name='FLAG_ncvqs', default=False
    )
    ncvqs = models.TextField(
        verbose_name='ncvqs', null=True, blank=True, default=''
    )


    brand_src = models.CharField(
        max_length=50, verbose_name='brand_src',
        null=True, blank=True, default=''
    )
    series_src = models.CharField(
        max_length=50, verbose_name='series_src',
        null=True, blank=True, default=''
    )
    model_src = models.CharField(
        max_length=50, verbose_name='model_src',
        null=True, blank=True, default=''
    )
    # 用来判断这个车型是依据map出来的还是翻译出来的
    FLAG_brand_model_convert = models.BooleanField(
        verbose_name='FLAG_brand_model_convert',
        default=False
    )
    brand = models.CharField(
        max_length=50, verbose_name='brand', null=True, blank=True, default=''
    )
    series = models.CharField(
        max_length=50, verbose_name='series', null=True, blank=True, default=''
    )
    model = models.CharField(
        max_length=50, verbose_name='model', null=True, blank=True, default=''
    )


    url_unique = models.CharField(
        max_length=400, verbose_name='url_unique', null=True, blank=True, default=''
    )

    # 原始的语句
    language_type_from_platform = models.CharField(
        max_length=5, verbose_name='language_type_from_platform',
        null=False, blank=False, choices=language_type_choices, default='zh'
    )
    title_zh = models.TextField(
        max_length=400, verbose_name='title_zh', null=True, blank=True, default=''
    )
    text_zh = models.TextField(
        max_length=1000, verbose_name='text_zh', null=True, blank=True, default=''
    )
    FLAG_translate_to_en = models.BooleanField(
        verbose_name='is_translate_to_en',
        null=False,
        blank=False,
        default=False
    )
    title_en = models.TextField(
        max_length=2000, verbose_name='title_en', null=True, blank=True, default=''
    )
    text_en = models.TextField(
        max_length=5000, verbose_name='text_en', null=True, blank=True, default=''
    )

    image_url = models.TextField(
        verbose_name='image_url_1', null=True, blank=True, default=''
    )

    already_request_img_content = models.BooleanField(
        default=False
    )

    class Meta:
        db_table = 'complaint'
        verbose_name = 'complaint'
        verbose_name_plural = verbose_name


class CuZuModel(BaseModel):
    """
    CuZuModel
    """
    info_category_choices = (
        ('forum', 'forum'),
        ('complaint', 'complaint'),
        ('cuzu', 'cuzu'),
    )
    language_type_choices = (
        ('zh', 'zh'),
        ('en', 'en')
    )

    sourceId = models.CharField(
        max_length=255, verbose_name='source_web_type', null=False, blank=False,
        default=''
    )
    update_time = models.DateTimeField(
        verbose_name='update_time',
        editable=True,
        auto_now=True
    )
    url_temp = models.CharField(
        max_length=255, verbose_name='url_temp', null=True, blank=True,
        default=''
    )
    price = models.CharField(
        max_length=255, verbose_name='price', null=True, blank=True,
        default=''
    )
    boughtdate = models.CharField(
        max_length=255, verbose_name='boughtdate', null=True, blank=True,
        default=''
    )
    address = models.CharField(
        max_length=255, verbose_name='address', null=True, blank=True,
        default=''
    )
    image_url = models.CharField(
        max_length=1000, verbose_name='image_url', null=True, blank=True,
        default=''
    )
    brand = models.CharField(
        max_length=255, verbose_name='brand', null=True, blank=True,
        default=''
    )
    series = models.CharField(
        max_length=255, verbose_name='series', null=True, blank=True,
        default=''
    )
    carspec_name = models.CharField(
        max_length=255, verbose_name='carspec_name', null=True, blank=True,
        default=''
    )
    title = models.TextField(
        verbose_name='title', null=True, blank=True,
        default=''
    )
    customer_voice = models.TextField(
        verbose_name='customer_voice', null=True, blank=True,
        default=''
    )
    URL = models.CharField(
        max_length=1000, verbose_name='URL', null=True, blank=True,
        default=''
    )
    title_en = models.TextField(
        verbose_name='title_en', null=True, blank=True,
        default=''
    )
    customer_voice_en = models.TextField(
        verbose_name='customer_voice_en', null=True, blank=True,
        default=''
    )
    llm_quality = models.TextField(
        verbose_name='llm_quality', null=True, blank=True,
        default=''
    )
    llm_csp = models.TextField(
        verbose_name='llm_csp', null=True, blank=True,
        default=''
    )
    llm_feeling = models.TextField(
        verbose_name='llm_feeling', null=True, blank=True,
        default=''
    )
    llm_quality_en = models.TextField(
        verbose_name='llm_quality_en', null=True, blank=True,
        default=''
    )
    llm_csp_en = models.TextField(
        verbose_name='llm_csp_en', null=True, blank=True,
        default=''
    )
    llm_feeling_en = models.TextField(
        verbose_name='llm_feeling_en', null=True, blank=True,
        default=''
    )

    class Meta:
        db_table = 'cuzu_django'
        verbose_name = 'cuzudjango'
        verbose_name_plural = verbose_name



























'''

class MediaModel(BaseModel):
    """
    CuZuModel
    """
    info_category_choices = (
        ('forum', 'forum'),
        ('complaint', 'complaint'),
        ('cuzu', 'cuzu'),
    )
    language_type_choices = (
        ('zh', 'zh'),
        ('en', 'en')
    )

    sourceId = models.CharField(
        max_length=255, verbose_name='source_web_type', null=False, blank=False,
        default=''
    )
    update_time = models.DateTimeField(
        verbose_name='update_time',
        editable=True,
        auto_now=True
    )
    url_temp = models.CharField(
        max_length=255, verbose_name='url_temp', null=True, blank=True,
        default=''
    )
    image_url = models.CharField(
        max_length=1000, verbose_name='image_url', null=True, blank=True,
        default=''
    )
    brand = models.CharField(
        max_length=255, verbose_name='brand', null=True, blank=True,
        default=''
    )
    series = models.CharField(
        max_length=255, verbose_name='series', null=True, blank=True,
        default=''
    )
    carspec_name = models.CharField(
        max_length=255, verbose_name='carspec_name', null=True, blank=True,
        default=''
    )
    title = models.TextField(
        verbose_name='title', null=True, blank=True,
        default=''
    )
    text = models.TextField(
        verbose_name='text', null=True, blank=True,
        default=''
    )
    URL = models.CharField(
        max_length=1000, verbose_name='URL', null=True, blank=True,
        default=''
    )
    title_en = models.TextField(
        verbose_name='title_en', null=True, blank=True,
        default=''
    )
    text_en = models.TextField(
        verbose_name='text_en', null=True, blank=True,
        default=''
    )
    nickname = models.CharField(
        max_length=500, verbose_name='nickname', null=True, blank=True,
        default=''
    )
    read_times = models.CharField(
        max_length=500, verbose_name='read_times', null=True, blank=True,
        default=''
    )
    llm_quality = models.TextField(
        verbose_name='llm_quality', null=True, blank=True,
        default=''
    )
    llm_csp = models.TextField(
        verbose_name='llm_csp', null=True, blank=True,
        default=''
    )
    llm_feeling = models.TextField(
        verbose_name='llm_feeling', null=True, blank=True,
        default=''
    )
    llm_quality_en = models.TextField(
        verbose_name='llm_quality_en', null=True, blank=True,
        default=''
    )
    llm_csp_en = models.TextField(
        verbose_name='llm_csp_en', null=True, blank=True,
        default=''
    )
    llm_feeling_en = models.TextField(
        verbose_name='llm_feeling_en', null=True, blank=True,
        default=''
    )

    class Meta:
        db_table = 'media_django'
        verbose_name = 'mediadjango'
        verbose_name_plural = verbose_name

'''

